package day13;

import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;


public class TestLoop {
    List<Object> list;
    @Before
    public void before(){
        list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        list.add("e");
    }

    @Test
    public void test1() {
        for (int i = 0; i < list.size(); i++) {
            //默认获取的值是object类型  需要强转
            System.out.println((String)list.get(i));
            Object o = list.get(i);

        }
    }


    @Test
    public void test2() {
        for(Object o : list){
            System.out.println(o);
        }
    }


    @Test
    public void test3() {
        //1.获取迭代器对象 iterator
        Iterator it = list.iterator();
        //2.it.next()  每次只取第一个(删除第一个)
        //it.hasNext()
        while(it.hasNext()){
            String s = (String) it.next();
            System.out.println(s);
        }
    }
}
